package band.wukong.practice.javase.core.io.typicalUsage;

import java.io.*;

/**
 * Desc:
 * Author: sunjs
 * Date: 2009-12-18 15:38:49
 */
public class StoringAndRecoveringData {
    static final String FILE_OUT = "src\\com\\jsun\\javase\\corepackage\\io\\testdir\\out.txt";

    public static void main(String[] args) throws IOException {
        DataOutputStream out = new DataOutputStream(
                new BufferedOutputStream(new FileOutputStream(FILE_OUT))
        );
        
        out.writeDouble(3.14159);
        // Only readUTF() will recover the Java-UTF String properly
        out.writeUTF("That is pi");
        out.writeDouble(1.41413);
        out.writeUTF("Square root of   2");
        out.close();

        DataInputStream in = new DataInputStream(
                new BufferedInputStream(new FileInputStream(FILE_OUT))
        );
        System.out.println(in.readDouble());
        System.out.println(in.readUTF());
        System.out.println(in.readDouble());
        System.out.println(in.readUTF());
    }
}
